#include<iostream>
#include<stdint.h>
#include<Snowstorm.h>

using namespace std;

ENGINE_VARS *ev;

void escape_handler()
{
	cout << "escape pressed!" << endl;
	EngineStop();
	return;
}

void space_handler()
{
	cout << "space pressed!" << endl;
	return;
}

void mouse_handler()
{
	//cout << "mouse left clicked!" << endl;
	cout << "screen x: " << v(screen_x) << endl;
	cout << "screen y: " << v(screen_y) << endl;

	return;
}

void control_handler()
{
	cout << "control pressed" << endl;
	return;
}

void window_close_clicked()
{
	cout << "close clicked" << endl;
	EngineStop();
}

int main()
{
	cout << "hello1!" << endl;
	
	// initialise the engine
	ev = EngineInitialise();
	//v(minimize_on_lost_focus) = true;
	v(lock_cursor_to_window) = true;
	//v(hide_cursor) = true;
	v(screen_type) = SCREEN_TYPE::WINDOWED;
	v(vsync) = true;

	// start it
	EngineStart(ev);

	// register escape key handler
	RegisterKeyReleaseEvent(VK_ESCAPE, escape_handler);
	//RegisterKeyReleaseEvent(VK_XBOXSTART, escape_handler);
	RegisterKeyPressEvent(VK_SPACE, space_handler);
	RegisterKeyPressEvent(1, mouse_handler);
	RegisterKeyHeldEvent(VK_RCONTROL, control_handler);
	RegisterWindowCloseEvent(window_close_clicked);

	// do the frames
	float time_counter = 0;
	while(EngineFrame())
	{
		// count if 1 second has passed
		if(time_counter > 1)
		{
			cout << "current FPS: " << v(current_FPS) << " last frame time: " << v(frame_time) << " time idle: " << v(frame_idle_time) << endl;
			time_counter = 0;
		}
		else
		{
			time_counter += v(frame_time);
		}
	}

	// engine ended
	cout << "engine stopped" << endl;

	//cin.get();
	return 0;
}